
<?php 
header("Content-Type:text/html;charset=utf-8");
include "../inc/page.class.php";
include_once '../inc/conn.php';
date_default_timezone_set('PRC');
?>
<html>
<head>

<title>userinfo</title>



<link href="../css/css.css" rel="stylesheet" type="text/css" />
<script type="text/JavaScript">

</script>
<link href="../css/style.css" rel="stylesheet" type="text/css" />
</head>
<SCRIPT language=JavaScript src="../js/select.js"></script>

</head>

<body>
<form name="fom1" id="fom1" method="post" action="">

				   　　<img src="../images/ico07.gif" width="20" height="18" />　请输入关键字:
		 
				     <input type="text" name="user_key" />
				     <select name="user_select">
						<option>姓名</option>
						
						<option>用户账号</option>
				
				  
  </select>
				
				
				<input type="submit" name="search" value="搜索" />
</form>


<?php 
/* 定义一个显示用户信息的方法 */
$query_str="SELECT * FROM `login_user` order by uid desc";
$result_all=$oa->query($query_str);
$total=mysql_num_rows($result_all);
$num=10;

$page=new Page($total, $num, "&id");
$dis_page='<table><tr><td align="left" width="600">'.$page->fpage(array(0,2)).'</td><td align="right" width="500">'.$page->fpage(array(4,5,6,7,8))."</td></tr></table>";
function list_userinfo($result,$dis_page){
	$nums=mysql_num_rows($result);
	if($nums==0)
	{
		echo "<font color=red>没有找到相关记录!</font>";
	}
	else{
			echo '<form name="fom"  id="fom" >';
			echo  '<td><table id="subtree1" style="DISPLAY: " width="100%" border="0" cellspacing="0" cellpadding="0">';
			echo   '    <tr>';
			echo'          <td><table width="97%" border="0" align="center" cellpadding="0" cellspacing="0">';
			echo'       <tr>
			               <td height="20"><span class="newfont07">选择：<a href="#" class="right-font08" onclick="selectAll();">全选</a>-<a href="#" class="right-font08" onclick="unselectAll();">反选</a></span>
	              <input name="Submit1" type="button" class="right-button08" value="删除所选用户" onclick="return delete_users();"/>
	              <input name="Submit2" type="button" class="right-button08" onclick="link();" value="添加用户"/></td>
       	    </tr>
              <tr>
                <td height="40" class="font42">
				<table width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#464646" class="newfont03">
				 <tr class="CTitle" >
                    	<td height="22" colspan="8" align="center" style="font-size:16px" bgcolor="#EEEEEE">用户详细列表</td>
                  </tr>
                  <tr bgcolor="#EEEEEE">
				    <td width="6%" align="center" height="30">选择</td>
                    <td width="12%">姓名</td>
					<td width="12%">帐号名</td>
                    <td width="12%">用户权限</td>
					<td width="10%">登录次数</td>
					<td width="15%">上次登录时间</td>
					<td width="15%">上次登录IP</td>
					<td width="20%"><div align="center">操作</div></td>
                  </tr>';
			
				 // $result=$oa->query($result);
				   while($row=mysql_fetch_array($result))
	 		     {
				  
                  
				  echo '<tr bgcolor="#FFFFFF">';
				  echo' <td height="20">';
				  $get_id= $row['uid'];
				  echo '<input type="checkbox" name="delid[]" value='.$get_id.'></td>';
                  echo '<td >'. $row['username'].'</td>';
				  echo '<td >'.$row['user_acc'].'</td>';
                  echo '<td>';
                  
                    switch(intval($row['prv_flag'])){
                    	case 0:
                    	echo "普通员工";
                         break;
                    	case 1:
                    	echo "部门主管";
                    	break;
                    	case 2:
                    	echo "系统管理员";
                    	break;
                    	
                    }
                    
                    echo '</td>';
                    echo '<td>'.$row['login_count'].'</td>';
                    echo '<td>';
					 
					if(!$row['last_time']=="")
					echo date("Y-m-d H:i:s",$row['last_time']);
					else
					echo "未知";
					
                    
                   echo   '</td>';
                   echo   '<td>'; 
                    if (($row['last_ip']) == ""){
                    	echo "未知";
                    }
                    else{
                    	echo $row['last_ip'];
                    }
                    echo '</td>';
                    //删除用户时超链接后面加了一个'|'目的是传到删除页那里面有一个分隔函数id转化为数组
                   echo '<td> <a href="user_update.php?uid='.$row['uid'].'">编辑用户</a> | <a href="delete_uid.php?id='.$get_id.'|'.'" onclick="return confirmd1();">删除用户</a></td>';
                   echo '</tr>';
				  }
           echo' </table></td></tr>
        <td>'
        .$dis_page.
        '</td>
       
     
      </table>';
      echo '</form>';
	}
}
?>
<?php
//判断提交之前查询所有用户信息
	 if(empty($_POST['search'])){
     $select="select * from login_user  order by uid desc {$page->limit}";
     $result=$oa->query( $select);
     list_userinfo($result,$dis_page);
     
}
//提交之后查询相关信息
    if(isset($_POST['search']))
	{
		$user_key=@addslashes(trim($_POST['user_key']));
		$user_select=@$_POST['user_select'];

		 if(!empty( $user_key))
		 {
			
				  if ($user_select == '姓名'){
				 
					   $key_sql="select * from login_user where username like '%$user_key%'  order by uid desc {$page->limit}";
				  }
					
		
				 if  ($user_select == '用户账号')
				 {
					$key_sql="select * from login_user where user_acc like '%$user_key%'  order by uid desc {$page->limit}";
				 }
				 
 			 $result_key=$oa->query($key_sql);
 			 list_userinfo($result_key,$dis_page);
		 	 }
	   }
	?>
</body>
</html>
